package com.db.gffxo.epi.repository;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import com.db.gffxo.epi.domain.EventFormat;
import com.db.gffxo.epi.repository.EventFormatDao;


public class EventFormatDaoGen extends SimpleJdbcDaoSupport implements EventFormatDao {

private final static String QUERY = "SELECT * FROM EventFormat order by eventtype";
private final static String REMOVEBYEventType = "DELETE FROM EventFormat WHERE EventType = ?";
private final static String QUERYBYEventType = "SELECT * FROM EventFormat WHERE EventType = ?";
private final static String INSERT = "INSERT INTO EventFormat(EventType, FormatterId, FormatterName, FormatterParams ) VALUES (?,?,?)";


	public void removeByEventType(String EventType) {
		getSimpleJdbcTemplate().update(REMOVEBYEventType, EventType);
	}


	public void insert(EventFormat eventFormat) {
		getSimpleJdbcTemplate().update(INSERT
			,eventFormat.getEventType()
			,eventFormat.getFormatterId()
			,eventFormat.getFormatterName()
			,eventFormat.getFormatterParams()
		);
	}

	public List<EventFormat> getEventFormat() {
		List<EventFormat> eventFormats = getSimpleJdbcTemplate().query(QUERY,
			new RowMapper<EventFormat>() {
				public EventFormat mapRow(ResultSet rs, int rowNum) throws SQLException {
				EventFormat eventFormat = new EventFormat();
				eventFormat.setEventType(rs.getString(1));
				eventFormat.setFormatterId(rs.getString(2));
				eventFormat.setFormatterName(rs.getString(3));
				eventFormat.setFormatterParams(rs.getString(4));
				return eventFormat;
			}
		});
		return eventFormats;
	}
	public List getEventFormatbyEventType(String EventType) {
		List eventFormats = getSimpleJdbcTemplate().query(QUERYBYEventType,
			new RowMapper<EventFormat>() {
				public EventFormat mapRow(ResultSet rs, int rowNum) throws SQLException {
				EventFormat eventFormat = new EventFormat();
				eventFormat.setEventType(rs.getString(1));
				eventFormat.setFormatterId(rs.getString(2));
				eventFormat.setFormatterName(rs.getString(3));
				eventFormat.setFormatterParams(rs.getString(4));
				return eventFormat;
			}
		}
		,EventType);
		return eventFormats;
	}
}